import * as fs from "fs";


export default class FileUtils {
    /** 判断文件或者目录是否存在 */
    static existsSync(path: string) {
        return fs.existsSync(path);
    }

    /** 复制文件 */
    static copy(src: string, dst: string, isForce?: boolean) {
        if (!isForce && fs.existsSync(dst)) {
            return console.warn(`file exists: ${dst}`);
        }
        return fs.writeFileSync(dst, fs.readFileSync(src));
    };

    /** 重命名文件 */
    static rename(src: string, dst: string) {
        if (!fs.existsSync(src)) {
            return console.warn(`file not exists: ${src}`);
        }
        return fs.renameSync(src, dst);
    };

    /** 读取文件 */
    static readFileSync(file: string) {
        return fs.readFileSync(file, 'utf-8');
    }

    /** 写入文件 */
    static writeFileSync(filePath: string, data: any) {
        return fs.writeFileSync(filePath, data);
    }
}

